﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace Client
{
    public partial class FormICSAdd : BasePopForm
    {
        QunYing.BLL.ICSA_Device bll_Device = new QunYing.BLL.ICSA_Device();
        public FormICSAdd()
        {
            InitializeComponent();
            //this.FormValidator.SetControlValitors(this.txt_设备ID, Spore.Validator.ValidatorDefaults.NotNull);
            this.FormValidator.SetControlValitors(this.txt_通信号码, Spore.Validator.ValidatorDefaults.Phone);
            //this.FormValidator.SetControlValitors(this.txt_接警号码, Spore.Validator.ValidatorDefaults.Phone);
            //this.FormValidator.SetControlValitors(this.txt_经销商, Spore.Validator.ValidatorDefaults.NotNull);
            this.FormValidator.SetControlValitors(this.txt_ORP门限值, Spore.Validator.ValidatorDefaults.Float);
            this.FormValidator.SetControlValitors(this.txt_PH门限值,Spore.Validator.ValidatorDefaults.Float);
            this.FormValidator.SetControlValitors(this.txt_报警间隔时间,Spore.Validator.ValidatorDefaults.Float);
            this.FormValidator.SetControlValitors(this.txt_钙反应门限值,Spore.Validator.ValidatorDefaults.Float);
            this.FormValidator.SetControlValitors(this.txt_温度门限值,Spore.Validator.ValidatorDefaults.Float);
        }


        protected override void OnLoad(EventArgs e)
        {
           
            //this.txt_经销商.Text = GlobalInfo.UserLoginInfo.用户ID;
            this.txt_通信号码.Focus();
            base.OnLoad(e);
        }


        private void btn__Click(object sender, EventArgs e)
        {
            if (!this.FormValidator.ValidAll()) return;
            if (bll_Device.Exists(this.txt_通信号码.Text.Trim()))
            {
                this.ep.SetError(this.txt_通信号码, "已经存在该设备ID!");
            }
            try
            {
                QunYing.Model.ICSA_Device model = new QunYing.Model.ICSA_Device();
                model.ICSA设备ID = this.txt_通信号码.Text;
                model.ORP传感器 = this.rpg_ORP传感器.Properties.Items[0].Enabled;
                decimal temp;
                if (decimal.TryParse(this.txt_ORP门限值.Text.Trim(), out temp))
                {
                    model.ORP门限值 = temp;
                }
                if (decimal.TryParse(this.txt_PH门限值.Text.Trim(), out temp))
                {
                    model.PH门限值 = temp;
                }
                if (decimal.TryParse(this.txt_钙反应门限值.Text.Trim(), out temp))
                {
                    model.钙反应器PH门限值 = temp;
                }
                if (decimal.TryParse(this.txt_温度门限值.Text.Trim(), out temp))
                {
                    model.温度门限值 = temp;
                }
                model.水循环传感器 = rgp_水循环传感器.Properties.Items[0].Enabled;
                model.水位传感器 = rgp_水位传感器.Properties.Items[0].Enabled;
                model.PH传感器 = rgp_PH传感器.Properties.Items[0].Enabled;
                model.钙反应PH传感器 = rpg_钙反应传感器.Properties.Items[0].Enabled;
                model.氧循环传感器 = rgp_氧循环传感器.Properties.Items[0].Enabled;
                model.温度控制模式 = this.cbe_温控模式.Text;
                model.所属经销商 ="未设置";
                model.报警接收手机号码 = "13800138000";
                if (decimal.TryParse(this.txt_报警间隔时间.Text.Trim(), out temp))
                {
                    model.报警重复间隔时间 = temp;
                }
                model.定时器1关闭时间 = tet_定时器1关闭.Time;
                model.定时器1开启时间 = tet_定时器1开启.Time;
                model.定时器2关闭时间 = tet_定时器2关闭.Time;
                model.定时器2开启时间 = tet_定时器2开启.Time;
                model.定时上报时间 = tet_上报时间.Time;
                model.开启定时上报 = this.rgp_定时上报.Properties.Items[0].Enabled;
                model.设备类型 = this.cbe_设备类型.Text;
                model.是否故障 = false;
                model.是否已售 = false;
                model.通信号码 = this.txt_通信号码.Text;
                model.报警接收手机号码 = "13800138000";
                bll_Device.Add(model);
                if (XtraMessageBox.Show(GlobalInfo.UserLookAndFeel, "设备添加成功！需要继续添加设备吗？", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                {
                    this.Close();
                }
                else
                {
                    this.txt_通信号码.SelectAll();
                    this.txt_通信号码.Focus();
                }
            }
            catch (Exception ex)
            {
                GlobalInfo.MsgBoxShowError("程序处理出现异常：" + ex.Message);
            }

        }

        private void sharpButton2_Click(object sender, EventArgs e)
        {
            if (XtraMessageBox.Show(GlobalInfo.UserLookAndFeel, "确定要关闭当前窗体吗？", "询问", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                this.Close();
            }

        }

      

        
    }
}